<!DOCTYPE html>
<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>订单列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/style/admin.css" media="all">
	<link rel="stylesheet" href="/style/list.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">

        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">商品名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" id="name" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search" onclick="SelectData()">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">规格名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name1" id="name1" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search" onclick="SelectData1()">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">

            <table class="layui-hide" id="test" lay-filter="test"></table>

            <script type="text/html" id="hyzf">
                {{#
                    var fn = function(v1,v2)
                    {
                        return v1-v2;
                    };
                }}
                <div style="color: #1E9FFF">{{ fn(d.price,d.vouchers) }}</div>
            </script>

            <script type="text/html" id="wdcj">
                {{#
                var fn = function(v1,v2,v3,v4)
                {
                return v1-v2-v3-v4;
                };
                }}
                <div style="color: #1E9FFF">{{ fn(d.price,d.vouchers,d.coupon,d.owner1) }}</div>
            </script>

            <script type="text/html" id="sdcj">
                {{#
                var fn = function(v1,v2)
                {
                return v1-v2;
                };
                }}
                <div style="color: #1E9FFF">{{ fn(d.owner4,d.aloeverashop) }}</div>
            </script>

            <script type="text/html" id="min">
                {{#
                var fn = function(v1,v2,v3,v4,v5,v6,v7)
                {
                return v1-v2-v3-v4-v5-v6-v7;
                };
                }}
                <div style="color: red">{{ fn(d.aloeverashop,d.share,d.coupon,d.cost,d.operat,d.consumption,d.redenvelope) }}</div>
            </script>

        </div>
    </div>
</div>
<script src="/layui/layui.js"></script>
<script src="/layui/jquery.min.js"></script>
<script src="/js/common.js"></script>
<style>
    .layui-body{overflow-y: scroll;}
	.laytable-cell-1-orderId{width:50px;}
</style>

<script>
    var table;
    layui.use('table', function(){
        table = layui.table
            ,form = layui.form;

        table.render({
            elem: '#test'
            ,url:'/goods?url=Spec%2FList&state=1'
			,cellMinWidth:80
            ,cols: [[
                {field:'id',width:60,title:'ID'}
                ,{field:'goodsName',width:150,title:'商品名称'}
                ,{field:'name',width:150,title:'规格名称'}
                ,{field:'price',title:'商 城 价',edit: 'text'}
                ,{field:'cost',title:'商品成本',edit: 'text'}
                ,{field:'operat',title:'运营成本',edit: 'text'}
                ,{field:'share',title:'分享赠',edit: 'text'}
                ,{field:'consumption',title:'消费赠',edit: 'text'}
                ,{field:'redenvelope',title:'随机红包',edit: 'text'}
				,{field:'coupon',title:'购物券',edit: 'text'}
				,{field:'vouchers',title:'代金券',edit: 'text'}
                ,{field:'owner1',title:'一星',edit: 'text'}
                ,{field:'owner2',title:'二星',edit: 'text'}
                ,{field:'owner3',title:'三星',edit: 'text'}
                ,{field:'owner4',title:'诚信',edit: 'text'}
                ,{field:'aloeverashop',title:'芦荟屋',edit: 'text'}
                ,{field:'hyzf',title:'会员支付', templet: '#hyzf', unresize: true}
                ,{field:'owner4',title:'微店差价', templet: '#wdcj', unresize: true}
                ,{field:'owner4',title:'实店差价',templet: '#sdcj', unresize: true}
                ,{field:'min',title:'最低利润', templet: '#min', unresize: true}
            ]]
            ,page: true
            ,id: 'testReload'
        });

        //监听单元格编辑
        table.on('edit(test)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
                //alert($(".laytable-cell-1-min").get());
            Edit(data.id,field,value);
        });


    });

    function Edit(id,key,value)
    {
        $.ajax({
            type: "POST",
            url: "/goodsjson",
            contentType: "application/json; charset=utf-8",
            data: "{\"url\": \"Spec/Set\",\"parm\":{\"id\": "+id+",\""+key+"\": "+value+"}}",
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.code != "000000") {
                    alert(data.errorDetail);
                }
            },
            error: function (message) {
                alert("提交数据失败！"+message);
            }
        });
        return true;
    }

    function SelectData() {
        //数据刷新
        var name=$('#name').val();
        var url="/goods?url=Spec%2FList&state=1&goodsName="+name;
        //alert(url);
        //执行重载
        table.reload('testReload', {
            url:url,
            page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    }

    function SelectData1() {
        //数据刷新
        var name=$('#name1').val();
        var url="/goods?url=Spec%2FList&state=1&name="+name;
        //alert(url);
        //执行重载
        table.reload('testReload', {
            url:url,
            page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    }

</script>


</body>
</html>